﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.TongShiWei.PigData;

namespace WinFormsApp1.TongShiWei.segmentationData
{
    public partial class SegmentationTime : Form
    {
        private const int ROWS = 6;
        private const int COLS = 7;
        private Button[,] buttons;
        public SegmentationTime()
        {
            InitializeComponent();
            // 设置窗口的最小和最大尺寸相同，以固定窗口大小
            this.MinimumSize = new Size(1200, 1000); // 设定窗口的最小尺寸
            this.MaximumSize = new Size(1200, 1000); // 设定窗口的最大尺寸

            // 设置窗口边框样式为固定单边框
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            buttons = new Button[ROWS, COLS];
            int i = 0;
            int y = 11;
            for (int row = 0; row < ROWS; row++)
            {
                for (int col = 0; col < COLS; col++)
                {
                    i++;
                    int buttonX = 10 + col * 150, buttonY = 130 + row * 100;
                    Button button = new Button();
                    button.Location = new System.Drawing.Point(buttonX, buttonY);
                    button.Size = new System.Drawing.Size(150, 100);
                    buttons[row, col] = button;
                    if (i > 31)
                    {
                        i = 1;
                        button.Text = "" + i + "";
                        y++;
                        button.Name = "2024-" + y + "-" + i + "";
                    }
                    else
                    {
                        button.Text = "" + i + "";
                        button.Name = "2024-" + y + "-" + i + "";
                    }
                    //button.Padding = new Padding(1, 5, 5, 5);
                    button.Click += new System.EventHandler(button1_Click);
                    this.Controls.Add(button);
                }
            }

            this.Size = new System.Drawing.Size(300, 300);
            ShowListData();
        }
        #region 显示按钮
        public async void ShowListData()
        {
            List<ShowButtonData> Button_Data = new List<ShowButtonData>()
            {
                new ShowButtonData{ButtonName_="小明",ButtonNum=10,ButtonTime="2024-11-1" },
                new ShowButtonData{ButtonName_="小红",ButtonNum=30,ButtonTime="2024-11-10"  },
                new ShowButtonData{ButtonName_="小路",ButtonNum=40,ButtonTime="2024-11-12"  },
                new ShowButtonData{ButtonName_="小威",ButtonNum=50,ButtonTime="2024-11-25"  },
                new ShowButtonData{ButtonName_="小刘",ButtonNum=60,ButtonTime="2024-11-30"  },
            };
            int x = 0;
            int y = 0;
            foreach (var item in Button_Data)
            {
                var DataNum = Convert.ToInt32(item.ButtonTime.Substring(8));
                var pnum = DataNum / 7;
                var bnum = DataNum % 7;
                buttons[pnum, (bnum - 1)].Text = "" + DataNum + "   计划宰杀头数   120" +
                    " \n操作人                 " +
   item.ButtonName_ + "    " + "\n总头数                    " + item.ButtonNum + "";
                y++;
            }
        }
        public class ShowButtonData
        {
            public string ButtonName_ { get; set; }
            public int ButtonNum { get; set; }
            public string ButtonTime { get; set; }
        }
        #endregion
        private void button1_Click(object sender, EventArgs e)
        {
            var buttonData = sender as Button;
            var ButtonName = buttonData.Name;
            SegmentationContext segmentationContext = new SegmentationContext(ButtonName);
            segmentationContext.Show();
        }
    }
}
